/*
 * Created on 30-ene-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.juanfrivaldes.cio2005.web;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 * @author root
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class RegistroUsuarioForm extends ActionForm {


		/**
		 * @return Returns the apellidos.
		 */
		public String getApellidos() {
			return apellidos;
		}
		/**
		 * @param apellidos The apellidos to set.
		 */
		public void setApellidos(String apellidos) {
			this.apellidos = apellidos;
		}
		/**
		 * @return Returns the email.
		 */
		public String getEmail() {
			return email;
		}
		/**
		 * @param email The email to set.
		 */
		public void setEmail(String email) {
			this.email = email;
		}
		/**
		 * @return Returns the nif.
		 */
		public String getNif() {
			return nif;
		}
		/**
		 * @param nif The nif to set.
		 */
		public void setNif(String nif) {
			this.nif = nif;
		}
		/**
		 * @return Returns the nombre.
		 */
		public String getNombre() {
			return nombre;
		}
		/**
		 * @param nombre The nombre to set.
		 */
		public void setNombre(String nombre) {
			this.nombre = nombre;
		}
		/**
		 * @return Returns the password.
		 */
		public String getPassword() {
			return password;
		}
		/**
		 * @param password The password to set.
		 */
		public void setPassword(String password) {
			this.password = password;
		}
		/**
		 * @return Returns the passwordCheck.
		 */
		public String getPasswordCheck() {
			return passwordCheck;
		}
		/**
		 * @param passwordCheck The passwordCheck to set.
		 */
		public void setPasswordCheck(String passwordCheck) {
			this.passwordCheck = passwordCheck;
		}
		/**
		 * @return Returns the telefono.
		 */
		public String getTelefono() {
			return telefono;
		}
		/**
		 * @param telefono The telefono to set.
		 */
		public void setTelefono(String telefono) {
			this.telefono = telefono;
		}
		/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 3256723961709410102L;


		private static Log log = LogFactory.getLog(RegistroUsuarioForm.class); 

		
		private String nombre;
		private String apellidos;
		private String email;
		private String password;
		private String passwordCheck;
		private String telefono;
		private String nif;
		
		
		public void reset(ActionMapping mapping, HttpServletRequest request) {
			
			nombre=null;
			apellidos=null;
			email=null;
			password=null;
			passwordCheck=null;
			telefono=null;
			nif=null;
		}


		public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
			ActionErrors errors = new ActionErrors();
			
			
			
			if (email==null 
				|| email.trim().equals("")){
				errors.add("email",new ActionMessage("registroUsuario.email.problema"));
			}
			
			else if (nombre==null 
					|| nombre.trim().equals("")){
					errors.add("nombre",new ActionMessage("registroUsuario.nombre.problema"));
				}
			
			else if (apellidos==null 
					|| apellidos.trim().equals("")){
					errors.add("apellidos",new ActionMessage("registroUsuario.apellidos.problema"));
				}
			
			else if (telefono==null 
					|| telefono.trim().equals("")){
					errors.add("telefono",new ActionMessage("registroUsuario.telefono.problema"));
				}
			
			else if (nif==null 
					|| nif.trim().equals("")){
					errors.add("nif",new ActionMessage("registroUsuario.nif.problema"));
				}
			
			else if (password==null 
					|| password.trim().equals("")||password.trim().length()<6){
					errors.add("nif",new ActionMessage("registroUsuario.password.problema"));
				}
			
			else if(passwordCheck==null || !password.equals(passwordCheck)){
				errors.add("nif",new ActionMessage("registroUsuario.passwordsDiferentes.problema"));
			}
			
			else if(nif.length()!=9){
				errors.add("nif",new ActionMessage("registroUsuario.nif.problema"));
			}
			
			else if(telefono.length()<9){
				errors.add("telefono",new ActionMessage("registroUsuario.telefono.problema"));
			}
						
			log.info("validacion de campos de registro de usuario finalizada");
			
			if(errors.size()>0)
				log.info("han ocurrido errores al validar");
			
			return errors;
		}

}
